<?php
if ( !defined('IN_ADMINCP') || !defined('IN_SEC') ){
	exit('Access Denied.');
}
$act = $_G['gp_act'];

if( $act == 'post_avatar' ){
	$path = 'avatars/admin/';
	$state = dupload('avatar', 'avatar', $path);

	$data = array(
		'img' => $state
	);
	$error = strlen($state) > 5 ? 0 : 1;

	if( !$error ){
		update('admincp_member', $admincp->adminid, array(
			'avatar' => $state
		));
	
		DB::Insert('admincp_member_activities', array(
			'adminid' => $admincp->adminid,
			'icon' => avatar($admincp->admin['avatar']),
			'title' => '更新了新的头像',
			'description' => '<img src="'.$state.'" />',
			'create_time' => SYS_TIME
		));
	}

	json($data, 'alert', $error);
}